#!/bin/bash

sourcepath="$1"
destpath="$2"
migrationtype="$3"
dirserv_prefs="/Library/Preferences/com.apple.openldap.plist"
slapconfig_path="${destpath}/usr/sbin/slapconfig"
sourcetype=""

if [ ! -d "${sourcepath}" ]; then
exit 0;
fi

if [ ! -d "${destpath}" ]; then
exit 0;
fi

if [ ! -f "${sourcepath}${dirserv_prefs}" ]; then
exit 0;
fi

if [ ! -x "${slapconfig_path}" ]; then
exit 1;
fi

if [ -z "${SRCSYSTEMVERSION}" ]; then
exit 1;
fi

case ${migrationtype} in
"os_install") sourcetype="System";;
"migration") sourcetype="Migration";;
*) exit 1;;
esac

DYLD_FALLBACK_FRAMEWORK_PATH="${destpath}/System/Library/PrivateFrameworks" DYLD_LIBRARY_PATH="${destpath}/usr/lib" "${slapconfig_path}" -migrateldapserver 0 "${sourcepath}" "${destpath}" "${SRCSYSTEMVERSION}" ${sourcetype}  en
